
#pragma once
//#include "..\..\FORGIPSDLL\FORGIPSDLL\DataFunction.h"
#include "DataFunction.h"
#define MAXLEN_24VRS 650
#define CRC_POLYNOMIAL_24 0x01864CFB
/* ssr update intervals ------------------------------------------------------*/
static const double ssrudint[16] = {1, 2, 5, 10, 15, 30, 60, 120, 240, 300, 600, 900, 1800, 3600, 7200, 10800};
class CRTCM3x 
{
public:
	CRTCM3x(void);
	~CRTCM3x(void);
public:
	void    time2str(gtime_t t, char *str, int n);
	gtime_t epoch2time(const double *ep);
	void    time2epoch(gtime_t t, double *ep);
	gtime_t gpst2time(int week, double sec);
	double  time2gpst(gtime_t t, int *week);

	char    *time_str(gtime_t t, int n);

	gtime_t timeadd  (gtime_t t, double sec);
	double  timediff (gtime_t t1, gtime_t t2);

	gtime_t utc2gpst (gtime_t t);



	gtime_t timeget  (void);



	int adjgpsweek(int week);


	void trace (int level, const char *format, ...);


	unsigned int getbitu(const unsigned char *buff, int pos, int len);
	int          getbits(const unsigned char *buff, int pos, int len);

	unsigned int crc32  (const unsigned char *buff, int len);
	unsigned int crc24q (const unsigned char *buff, int len);

	int init_rtcm   (rtcm_t *rtcm);
	void free_rtcm  (rtcm_t *rtcm);
	
	void adjweek(rtcm_t *rtcm, double tow);
	double adjcp(rtcm_t *rtcm, int sat, int freq, double cp);



	int test_staid(rtcm_t *rtcm, int staid);
	int obsindex(obs_t *obs, gtime_t time, int sat);
	unsigned char snratio(double snr);
	int lossoflock(rtcm_t *rtcm, int sat, int freq, int lock);

	int satno(int sys, int prn);
	void adjday_glot(rtcm_t *rtcm, double tod);

	gtime_t gpst2utc(gtime_t t);
	
	double cp_pr(double cp, double pr_cyc);

	int locktime(gtime_t time, gtime_t *lltime, unsigned char LLI);

	int to_lock(int lock);
	
	int to_code1_gps(unsigned char code);
	
	int to_code2_gps(unsigned char code);

	int satsys(int sat, int *prn);

	void setbitu(unsigned char *buff, int pos, int len, unsigned int data);
	void setbits(unsigned char *buff, int pos, int len, int data);
	void set38bits(unsigned char *buff, int pos, double value);

	int gen_rtcm3(rtcm_t *rtcm, int type, int sync);
	int encode_rtcm3(rtcm_t *rtcm, int type, int sync);
	int encode_ssr_head(int type, rtcm_t *rtcm, int sys, int nsat, int sync, int iod, double udint, int refd, int provid, int solid);
	int encode_ssr4(rtcm_t *rtcm, int sys, int sync,int type);//grid corrections
};